<?php
/**
 * 默认展示页面
 *
 *
 *
 * @网店运维提供技术支持 授权请购买shopnc授权
 * @license    http://www.shopwwi.com
 * @link       交流群号：111731672
 */


defined('ByShopWWI') or exit('Access Invalid!');
class silverControl extends BaseHomeControl{
	

    public function indexOp(){
        Tpl::output('index_sign','silver');
        Language::read('home_index_index');

        //专题输出
        $goods_class= Model('goods_class');
        $date['gc_name']=array(array('like','茶具系列%'),array('like','银品生活%'),array('like',
            '宗教文化%'),array('like','家居摆件%'),array('like','皇家饰品%'), 'or');


        $goods_class_list= $goods_class->goods_list($date);

        $teaSet=$goods_class_list['teaSet']; $silverLife= $goods_class_list['silverLife'];
        $religCulture=$goods_class_list['religCulture']; $home=$goods_class_list['home'];  $queen=$goods_class_list['queen'];
		$sort = "";
		
		if(isset($_GET["time"])){
			if($_GET["time"] == "time_up"){
				$sort = 'goods_addtime asc';
			}
			if($_GET["time"] == "time_down"){
				$sort = 'goods_addtime desc';
			}
		}else{
            $sort = 'goods_addtime desc';
        }
		
		if(isset($_GET["price"])){
			if($_GET["price"] == "price_height"){
				$sort = 'goods_price desc';
			}
			if($_GET["price"] == "price_low"){
				$sort = 'goods_price asc';
			}
		}

		
        //茶具系列
        $condition=array('gc_id'=> $teaSet);
        $goods_list_teaSet=$this->silver_class($condition,$order = $sort);

        //银品生活
        $condition=array('gc_id'=> $silverLife);
        $goods_list_silverLife=$this->silver_class($condition,$order = $sort);

        //宗教文化
        $condition=array('gc_id'=> $religCulture);
        $goods_list_religCulture=$this->silver_class($condition,$order = $sort);

        //家居摆件
        $condition=array('gc_id'=> $home);
        $goods_list_home=$this->silver_class($condition,$order = $sort);

        //皇家饰品
        $condition=array('gc_id'=> $queen);
        $goods_list_queen=$this->silver_class($condition,$order = $sort);
		


        Tpl::output('all', 'hover');
        Tpl::output('queen',$goods_list_queen);
        Tpl::output('home',$goods_list_home);
        Tpl::output('religCulture',$goods_list_religCulture);
        Tpl::output('silverLife',$goods_list_silverLife);
        Tpl::output('teaSet',$goods_list_teaSet);
        Tpl::showpage('silver');
    }

    //茶具系列
    public function teaSetOp(){
        Tpl::output('index_sign','silver');
        $model_order= Model('goods');
        $goods_class= Model('goods_class');
        $date['gc_name']=array(array('like','茶具系列%'),array('like','银品生活%'),array('like',
            '宗教文化%'),array('like','家居摆件%'),array('like','皇家饰品%'), 'or');

        $goods_class_list= $goods_class->goods_list($date);
        $teaSet= $goods_class_list['teaSet'];
        $condition=array('gc_id'=> $teaSet);
        if(isset($_GET['price']) && $_GET['price']=='price_height') {
            $goods_list=$this->silver_class($condition, $order ='goods_price asc');
        }elseif(isset($_GET['price']) && $_GET['price']=='price_low'){
            $goods_list=$this->silver_class($condition, $order ='goods_price desc');
        }elseif(isset($_GET['time']) && $_GET['time']=='time_up'){
            $goods_list=$this->silver_class($condition, $order ='goods_addtime asc');
        }elseif (isset($_GET['time']) && $_GET['time']=='time_down'){
            $goods_list=$this->silver_class($condition, $order ='goods_addtime desc');
        }else{
            $goods_list=$this->silver_class($condition, $order ='goods_addtime desc');
        }

        Tpl::output('img','/images/inner-t1.jpg');
        Tpl::output('goods_list',$goods_list);
        Tpl::output('teaSet_class','hover');
        Tpl::output('op',substr(__FUNCTION__,0,strlen(__FUNCTION__)-2));
//        Tpl::output('show_page',$model_order->showpage());
        Tpl::showpage('class_silver');
    }

    //银品生活
    public function silverLifeOp(){
        Tpl::output('index_sign','silver');
        $model_order= Model('goods');
        $goods_class= Model('goods_class');
        $date['gc_name']=array(array('like','茶具系列%'),array('like','银品生活%'),array('like',
            '宗教文化%'),array('like','家居摆件%'),array('like','皇家饰品%'), 'or');

        $goods_class_list= $goods_class->goods_list($date);
        $silverLife= $goods_class_list['silverLife'];
        $condition=array('gc_id'=> $silverLife);
        if(isset($_GET['price']) && $_GET['price']=='price_height') {
            $goods_list=$this->silver_class($condition, $order ='goods_price asc');
        }elseif(isset($_GET['price']) && $_GET['price']=='price_low'){
            $goods_list=$this->silver_class($condition, $order ='goods_price desc');
        }elseif(isset($_GET['time']) && $_GET['time']=='time_up'){
            $goods_list=$this->silver_class($condition, $order ='goods_addtime asc');
        }elseif (isset($_GET['time']) && $_GET['time']=='time_down'){
            $goods_list=$this->silver_class($condition, $order ='goods_addtime desc');
        }else{
            $goods_list=$this->silver_class($condition, $order ='goods_addtime desc');
        }

        Tpl::output('img','/images/inner-t2.jpg');
        Tpl::output('goods_list',$goods_list);
        Tpl::output('silverLife_class','hover');
        Tpl::output('op',substr(__FUNCTION__,0,strlen(__FUNCTION__)-2));
        Tpl::output('show_page',$model_order->showpage());
        Tpl::showpage('class_silver');
    }

    //宗教文化
    public function religCultureOp(){
        Tpl::output('index_sign','silver');
        $model_order= Model('goods');
        $goods_class= Model('goods_class');
        $date['gc_name']=array(array('like','茶具系列%'),array('like','银品生活%'),array('like',
            '宗教文化%'),array('like','家居摆件%'),array('like','皇家饰品%'), 'or');

        $goods_class_list= $goods_class->goods_list($date);
        $religCulture= $goods_class_list['religCulture'];
        $condition=array('gc_id'=> $religCulture);
        if(isset($_GET['price']) && $_GET['price']=='price_height') {
            $goods_list=$this->silver_class($condition, $order ='goods_price asc');
        }elseif(isset($_GET['price']) && $_GET['price']=='price_low'){
            $goods_list=$this->silver_class($condition, $order ='goods_price desc');
        }elseif(isset($_GET['time']) && $_GET['time']=='time_up'){
            $goods_list=$this->silver_class($condition, $order ='goods_addtime asc');
        }elseif (isset($_GET['time']) && $_GET['time']=='time_down'){
            $goods_list=$this->silver_class($condition, $order ='goods_addtime desc');
        }else{
            $goods_list=$this->silver_class($condition, $order ='goods_addtime desc');
        }

        Tpl::output('img','/images/inner-t3.jpg');
        Tpl::output('religCulture_class','hover');
        Tpl::output('op',substr(__FUNCTION__,0,strlen(__FUNCTION__)-2));
        Tpl::output('goods_list',$goods_list);
        Tpl::output('show_page',$model_order->showpage());
        Tpl::showpage('class_silver');
    }

    //家居摆件
    public function homeOp(){
        Tpl::output('index_sign','silver');
        $model_order= Model('goods');
        $goods_class= Model('goods_class');
        $date['gc_name']=array(array('like','茶具系列%'),array('like','银品生活%'),array('like',
            '宗教文化%'),array('like','家居摆件%'),array('like','皇家饰品%'), 'or');

        $goods_class_list= $goods_class->goods_list($date);
        $home= $goods_class_list['home'];
        $condition=array('gc_id'=> $home);
        if(isset($_GET['price']) && $_GET['price']=='price_height') {
            $goods_list=$this->silver_class($condition, $order ='goods_price asc');
        }elseif(isset($_GET['price']) && $_GET['price']=='price_low'){
            $goods_list=$this->silver_class($condition, $order ='goods_price desc');
        }elseif(isset($_GET['time']) && $_GET['time']=='time_up'){
            $goods_list=$this->silver_class($condition, $order ='goods_addtime asc');
        }elseif (isset($_GET['time']) && $_GET['time']=='time_down'){
            $goods_list=$this->silver_class($condition, $order ='goods_addtime desc');
        }else{
            $goods_list=$this->silver_class($condition, $order ='goods_addtime desc');
        }

        Tpl::output('img','/images/inner-t4.jpg');
        Tpl::output('goods_list',$goods_list);
        Tpl::output('home_class','hover');
        Tpl::output('op',substr(__FUNCTION__,0,strlen(__FUNCTION__)-2));
        Tpl::output('show_page',$model_order->showpage());
        Tpl::showpage('class_silver');
    }

    //皇家饰品
    public function queenOp(){
        Tpl::output('index_sign','silver');
        $model_order= Model('goods');
        $goods_class= Model('goods_class');
        $date['gc_name']=array(array('like','茶具系列%'),array('like','银品生活%'),array('like',
            '宗教文化%'),array('like','家居摆件%'),array('like','皇家饰品%'), 'or');

        $goods_class_list= $goods_class->goods_list($date);
        $queen= $goods_class_list['queen'];
        $condition=array('gc_id'=> $queen);
        if(isset($_GET['price']) && $_GET['price']=='price_height') {
            $goods_list=$this->silver_class($condition, $order ='goods_price asc');
        }elseif(isset($_GET['price']) && $_GET['price']=='price_low'){
            $goods_list=$this->silver_class($condition, $order ='goods_price desc');
        }elseif(isset($_GET['time']) && $_GET['time']=='time_up'){
            $goods_list=$this->silver_class($condition, $order ='goods_addtime asc');
        }elseif (isset($_GET['time']) && $_GET['time']=='time_down'){
            $goods_list=$this->silver_class($condition, $order ='goods_addtime desc');
        }else{
            $goods_list=$this->silver_class($condition, $order ='goods_addtime desc');
        }

        Tpl::output('img','/images/inner-t5.jpg');
        Tpl::output('queen_class','hover');
        Tpl::output('op',substr(__FUNCTION__,0,strlen(__FUNCTION__)-2));
        Tpl::output('goods_list',$goods_list);
        Tpl::output('show_page',$model_order->showpage());
        Tpl::showpage('class_silver');
    }


    //专题分类 hyy
    private function silver_class($condition, $order=''){
        Tpl::output('index_sign','silver');
        $condition['goods_state']= 1;  //商品上架
        $goods_model=Model('goods');
        $goods= $goods_model->getGoodsCommonList($condition, $field = '*', $group = '',$order, $limit = '', $page = '',
            $count = 0);
        foreach ($goods as $_key => $_value){//hzx 2017-2-17 add
            $condition['goods_commonid']=$_value['goods_commonid'];
            $goods_info = $goods_model->getGoodsInfo($condition,$field);
            $goods[$_key]['goods_id']= $goods_info['goods_id'];
        }
//        $property= array();
//        foreach ($goods as $_key => $_value){
//        if($_value['spec_name'] != "N;"){
//            $property[$_value['goods_id']]= $_value['goods_commonid'];
//            $lenth=explode(' ', $_value['goods_name']) ;
//            $_value['goods_name']= preg_replace('/'.$lenth[count($lenth)-1].'/',' ',$_value['goods_name']);
//            $goods[$_key]['goods_name']= $_value['goods_name'];
//
//        }
//      }

//
//        // 删除重复规格排列
//        $property= array_unique($property);
//        if (!empty($property)){
//            foreach ($goods as $k=>$v){
//                foreach ( array_keys($property) as $key=>$value){
//                    if ($v['goods_id']==$value){
//                        unset($goods[$k]);
//                    }
//                }
//            }
//        }

        return $goods;

    }






}
